#include "myposix.h"

mqd_t posix_create(void)
{
    mqd_t mqd = -1;
	struct mq_attr attr;
	attr.mq_flags = 0;
	attr.mq_maxmsg = 10;
	attr.mq_msgsize = 256;
	attr.mq_curmsgs = 0;

	mqd = mq_open(POSIXFILE, O_CREAT|O_RDWR,0666, &attr);
    printf("%s|%s|%d,mqd = %d\n",__FILE__, __func__, __LINE__,mqd);
    return mqd;
}

int posix_send(mqd_t mqd, char *buf, int len)
{
    int ret = -1;
    if((ret = mq_send(mqd, buf, len, 0)) == -1)
	{
		perror("mq_send error");
		exit(-1);
	}
   return ret;
}

void posix_final(mqd_t mqd)
{
	if(-1 != mqd)
	{
		mq_close(mqd);
		mq_unlink(POSIXFILE);
	    mqd = -1;	
	}
}